package cn.tedu.micro.service.common;

import lombok.Data;

import java.io.Serializable;

/**
 * {
 *     "state":200,
 *     "data":null,
 *     "msg":"ok"
 * }
 * @param <T>
 */
@Data
public class JsonResult<T> implements Serializable {
   private Integer state;
   private String message;
   private T data;

    public static JsonResult ok(){
        JsonResult<Object> jsonResult = new JsonResult<>();
        jsonResult.setState(200);
        jsonResult.setMessage("OK");
        jsonResult.setData(null);
        return jsonResult;
    }
    public static JsonResult ok(String message){
        JsonResult<Object> jsonResult = new JsonResult<>();
        jsonResult.setState(200);
        jsonResult.setMessage(message);
        jsonResult.setData(null);
        return jsonResult;
    }
    public static JsonResult fail(){
        JsonResult<Object> jsonResult = new JsonResult<>();
        jsonResult.setState(500);
        jsonResult.setMessage("fail");
        jsonResult.setData(null);
        return jsonResult;
    }
    public static JsonResult fail(String message){
        JsonResult<Object> jsonResult = new JsonResult<>();
        jsonResult.setState(500);
        jsonResult.setMessage(message);
        jsonResult.setData(null);
        return jsonResult;
    }
}
